﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;
using FishServe.Core;

namespace FishServe.Client.Application
{
    public class ApplicationActivator
    {
        public ApplicationActivator()
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
        }

        public bool Start( string applicationDir, string releaseManifestFilename )
        {
            ReleaseManifest releaseManifest = ReleaseManifestReader.Read(applicationDir, releaseManifestFilename);
            
            foreach (ModuleManifest moduleManifest in releaseManifest.ModuleManifests)
            {
                if (moduleManifest.ManifestType == ModuleManifestType.Application)
                {
                    ModuleLoader moduleLoader = new ModuleLoader(applicationDir);
                    ModuleManifestResolver moduleManifestResolver = new ModuleManifestResolver(applicationDir, releaseManifest);

                    ApplicationModule applicationModule = new ApplicationModule(moduleLoader, moduleManifestResolver);
                    break;
                }
            }

            return true;
        }
    }
}
